home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char SccsId[]= "@(#)rule_create.c V1.13 3/13/95";
- #endif
-
- #include <windows.h>
- /* */
- /* */
- /* file name - rule_create.c */
- /* */
- /* This example program demostrates how to programatically create */
- /* and modify rules for a view and its objects. */
- /* */
-
- #include "std.h"
- #include "dvstd.h"
- #include "dvtools.h"
- #include "Tfundecl.h"
- #include "VOfundecl.h"
- #include "dvrule.h"
-
- /* Functions defined in rule_create.c */
-
- /*
- * MAIN PROGRAM
- */
- int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow )
- {
- VIEW view;
- RULE_CONDITION cond;
- RULE_ACTION action;
- OBJECT drawing, rule, menu_obj, quit_obj;
- ADDRESS *vdplist;
- int numvdps, event_type, cond_type, action_type;
- VARDESC vdp;
- DSVAR dsv;
-
- int argc;
- char **argv;
- char mes_str[100];
-
- make_argv(&argc,&argv,GetCommandLine());
- TInit ((char *) NULL, (char *) NULL); /* use DVPATH config var */
-
- view = TviLoad ("base_wo_ru.v");
- drawing = TviGetDrawing (view);
-
- /* */
- /* Add the rule : */
- /* On: V_RE_DRAW If: V_RC_ALWAYS Do: V_RA_STOP_DYNAMICS */
- /* to the view */
- /* */
-
- /* Create a default rule */
- rule = VOruCreate ();
-
- /* Set the appropriate info to the rule. Note: V_RC_ALWAYS
- | and V_RA_STOP_DYNAMICS both don't need any args
- */
- VOruSetInfo (rule, V_R_EVENT, (int) V_RE_DRAW, V_R_CONDITION,
- (int) V_RC_ALWAYS, (RULE_ARG) 0, (RULE_ARG) 0, (RULE_ARG) 0,
- V_R_ACTION, (int) V_RA_STOP_DYNAMICS,
- (RULE_ARG) 0, (RULE_ARG) 0, V_END_OF_LIST);
-
- /* Append the rule to the view's rule deque */
- VOruAddToOb (drawing, rule, -1);
-
- /* */
- /* Add the following rules to the menu input object named 'menu.obj' */
- /* On: V_RE_DONE If: Obj's Var = <1.0> */
- /* Do: Go to View <sub1.v> */
- /* On: V_RE_DONE If: Obj's Var = <2.0> */
- /* Do: Overlay <dyn_toggle.obj> from <sub2.v> */
- /* */
-
- /* Get the menu input object named 'menu.obj' */
- menu_obj = TdrGetNamedObject (drawing, "menu.obj");
-
- /* Get the menu input object's vdp and dsv */
- VOinGetVarList (menu_obj, &vdplist, &numvdps);
- vdp = (VARDESC) vdplist[0];
- dsv = (DSVAR) TvdGetDataSourceVariable (vdp);
-
- /* Create a default rule */
- rule = VOruCreate ();
- VOruSetInfo (rule, V_R_EVENT, (int) V_RE_DONE, V_R_CONDITION,
- (int) V_RC_DSV_VALUE, (RULE_ARG) dsv,
- (RULE_ARG) V_RC_EQUAL, (RULE_ARG) "1.0",
- V_R_ACTION, (int) V_RA_NEXT, (RULE_ARG) "sub1.v",
- (RULE_ARG) 0, V_END_OF_LIST);
-
- /* Append to the menu_obj's rule deque */
- VOruAddToOb (menu_obj, rule, -1);
-
- /* Create a default rule */
- rule = VOruCreate ();
- VOruSetInfo (rule, V_R_EVENT, (int) V_RE_DONE, V_R_CONDITION,
- (int) V_RC_DSV_VALUE, (RULE_ARG) dsv,
- (RULE_ARG) V_RC_EQUAL, (RULE_ARG) "2.0",
- V_R_ACTION, (int) V_RA_OVERLAY_OBJ,
- (RULE_ARG) "dyn_toggle.obj", (RULE_ARG) "sub2.v",
- V_END_OF_LIST);
-
- /* Append to the menu_obj's rule deque */
- VOruAddToOb (menu_obj, rule, -1);
-
-
- /* */
- /* Add rule to the object named 'quit.obj' to quit prototype */
- /* */
-
- /* Get the object named 'quit.obj' */
- quit_obj = TdrGetNamedObject (drawing, "quit.obj");
-
- /* Create a default rule */
- rule = VOruCreate ();
- VOruSetInfo (rule, V_R_EVENT, (int) V_RE_PICK, V_R_CONDITION,
- (int) V_RC_ALWAYS, (RULE_ARG) 0, (RULE_ARG) 0, (RULE_ARG) 0,
- V_R_ACTION, (int) V_RA_QUIT, (RULE_ARG) 0, (RULE_ARG) 0,
- V_END_OF_LIST);
-
- /* Append to the quit_obj's rule deque */
- VOruAddToOb (quit_obj, rule, -1);
-
- /* */
- /* Now for example, if we want to change menu_obj's second rule */
- /* from --> On: V_RE_DONE If: Obj's Var = <2.0> */
- /* Do: Overlay <dyn_toggle.obj> from <sub2.v> */
- /* to --> On: V_RE_DONE If: Obj's Var => <2.0> */
- /* Do: Overlay <dyn_menu.obj> from <sub2.v> */
- /* */
-
- /* First, get the second rule of menu_obj */
- rule = VOruGetFromOb (menu_obj, (int)2);
-
- /* Get the rule's V_R_CONDITION and V_R_ACTION info */
- VOruGetInfo (rule, V_R_EVENT, &event_type, V_R_CONDITION,
- &cond_type, &cond.arg[0], &cond.arg[1], &cond.arg[2],
- V_R_ACTION, &action_type, &action.arg[0],
- &action.arg[1], V_END_OF_LIST);
-
- /* Change the second arg of condition */
- cond.arg[1] = (RULE_ARG) V_RC_GREATER_EQUAL_THAN;
-
- /* Allocate space for the new object name */
- action.arg[0] = (RULE_ARG) S_ALLOC ((strlen ("dyn_menu.obj") + 1)
- * sizeof (char));
- /* Copy the new object name into the first arg of action */
- strcpy ((char *) action.arg[0], "dyn_menu.obj");
-
- /* Set the rule info again with the new condition and action info */
- VOruSetInfo (rule, V_R_EVENT, event_type, V_R_CONDITION,
- cond_type, cond.arg[0], cond.arg[1], cond.arg[2],
- V_R_ACTION, action_type, action.arg[0],
- action.arg[1], V_END_OF_LIST);
-
- sprintf (mes_str,"Added and modified rules...\n");
- strcat (mes_str,"Saving \"base_w_ru.v\" ...\n");
- strcat (mes_str,"Use DV-Draw or DV-Play to display.\n");
- MessageBox (
- GetFocus (),
- mes_str,
- "rule_create:",
- MB_OK
- );
- TviASCIISave (view, "base_w_ru.v");
-
- TviDestroy (view);
- TTerminate ();
- return EXIT_OK;
- }
-